# 钟奕升
# 课堂练习20240407异常处理

import math

try:
    a = float(input("请输入一个数：a= "))
    b = math.sqrt(a)
    print("a=", a, "b=", b)
except Exception as err09:
    print(err09)

print("开始start")
x = float(input("x="))
try:
    print("除，divided")
    n = 1 / x
    print("完成finish")
except Exception as err_c:
    print(err_c)

print("-------------以下是抛出异常的代码----------------")
while 1:
    try:
        n = 0
        n = int(input("n="))
        if n < 0:
            raise Exception("负数不能开平方，获得的n为负，不予处理")
        break
    except Exception as 错误信息:
        print(错误信息)

print(math.sqrt(n))
print("以下是简单异常语句")
try:
    w = 0
    w = int(input("w="))
    if W < 0:
        raise Exception()
except:
    print("此处有异常")
print("The end!!")
